---
title: Retrieve and consume a stored web context
summary: Get end-to-end process on SAIF.Services.WCF.Services.WebContextService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-22
operation_id: OP-009
trigger: Caller invokes `Get` over the `WebContext` route.
---

# OP-009: Retrieve and consume a stored web context

Get is invoked over the `WebContext` route on `SAIF.Services.WCF.Services.WebContextService`; this page documents the process end to end, from route dispatch to the message the caller receives.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-009 |
| **Trigger** | Caller invokes `Get` over the `WebContext` route. |
| **Entry operation** | [`Get`](../contracts/web-context-service.md#get) |
| **Owning component** | `SAIF.Services.WCF.Services.WebContextService.Get` |
| **Inputs** | Request message parts listed below |
| **Outputs** | The web context for the given application and session, then destroyed. |
| **Failure behavior** | Generic SOAP fault, per [Faults and error pipeline](../faults.md) |

## Request and response

| Direction | Element | Type | Declared in | Notes |
| --- | --- | --- | --- | --- |
| Request | `applicationName` | `string` | BCL (`System`) | Application name portion of the context key. (Yes) |
| Request | `sessionId` | `string` | BCL (`System`) | Session id portion of the context key. (Yes) |
| Response | `IWebContext` | `IWebContext` | External contracts assembly (`SAIF.Services.WCF.Contracts` / framework closure) ** | The web context for the given application and session, then destroyed. |

<!-- Types declared in `SAIF.Services.WCF.Contracts` are attributed to `SAIF.Framework.Core`, inferred from source and package references and marked `*`; their members are not enumerated because the external declaration was not read, marked `**`. -->

## Steps

1. Constructor resolves the SQL Server `NETFRAMEWORK`/`APPM` connection and opens a unit of work plus a `Repository<WebContextItem>` ([BR-WCF-002](../business-rules.md#br-wcf-002-per-request-configuration-and-connection-resolution)).
2. `Enforce.ArgumentNotNullOrEmpty` on `applicationName` and `sessionId` ([BR-WCF-014](../business-rules.md#br-wcf-014-web-context-operations-require-identifying-arguments)).
   - On failure: `ArgumentNullException`, logged and surfaced as a generic SOAP fault.
3. Query all `WebContextItem` rows for the application and session into a list, outside the unit of work.
4. Find the item named `__SAIFPID`; pass its value (or null) to `CreateContext`, which seeds the context id from that value or generates a new GUID ([BR-WCF-015](../business-rules.md#br-wcf-015-context-identity-comes-from-a-stored-pid-or-a-new-guid)).
5. `unitOfWork.Begin()` opens the boundary for the delete loop.
6. For each item: copy it into the context unless its name is one of `sourceApp`, `sourceView`, `targetApp`, `targetView` ([BR-WCF-016](../business-rules.md#br-wcf-016-navigation-keys-are-never-returned-in-context)), then `repository.Delete(x)` unconditionally — including the excluded names and `__SAIFPID` ([BR-WCF-017](../business-rules.md#br-wcf-017-web-context-rows-are-read-once)).
7. `unitOfWork.Commit()`; return the context.
   - On failure: logged by the installed error handler, surfaced as a generic SOAP fault; the transaction rolls back on `Dispose`, so the read items survive and the read is not idempotent across a failure.*

## Process flow

The following diagram visualizes this process's control flow.

```mermaid
flowchart TD
    A["Resolve SQL connection and<br>open Repository&lt;WebContextItem&gt;"]
    B["Validate applicationName and sessionId"]
    C["Query stored context items for<br>application and session"]
    D1{"__SAIFPID item present?"}
    D2["Seed the context id from<br>the __SAIFPID item's value"]
    D3["Generate a new GUID<br>for the context id"]
    D["CreateContext constructs the context<br>with the seeded or generated id"]
    E["Begin transaction for delete loop"]
    F1{"Item name is one of<br>sourceApp, sourceView,<br>targetApp, targetView?"}
    F2["Excluded: do not copy<br>the item into the context"]
    F3["Not excluded: copy the<br>item into the context"]
    F4["repository.Delete(x) unconditionally —<br>including the excluded names and __SAIFPID"]
    G["unitOfWork.Commit(); return the context."]
    A --> B
    B --> C
    C --> D1
    D1 -->|"Present"| D2
    D1 -->|"Absent"| D3
    D2 --> D
    D3 --> D
    D --> E
    E --> F1
    F1 -->|"Yes"| F2
    F1 -->|"No"| F3
    F2 --> F4
    F3 --> F4
    F4 --> G
```

## Transaction and side effects

| Aspect | Finding |
| --- | --- |
| Unit of work | `SqlServerUnitOfWorkFactory` (`NETFRAMEWORK`/`APPM`) |
| Commit point | `unitOfWork.Commit()` after the delete loop |
| Records written | `WebContextItem` (read, then deleted) |
| Downstream calls | None |
| Shared state touched | None |
| Repeat-call behavior | A repeat call after a successful `Get` returns a fresh context because the rows were deleted |

## Logging

| Surface | Written content |
| --- | --- |
| `ErrorLogErrorHandler` → `LogService` | Failure-path exception logging only, carrying method signature, calling user and exception detail; see [Faults and error pipeline](../faults.md) |

## Faults and error handling

| Failure | Fault type the caller receives | Produced by | Source |
| --- | --- | --- | --- |
| `ArgumentNullException` | `Generic SOAP fault` | The operation itself, via `Enforce` | src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs |
| SQL Server/NHibernate exception | `Generic SOAP fault` | The `ErrorLogErrorHandler` installed by `[LogErrorBehavior]` | src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs |

## Authorization

| Requirement | Enforced by | Source | Applies to |
| --- | --- | --- | --- |
| [None in code](../authentication-authorization.md#authorization-enforcement) | IIS authentication on the deployment (see [Activation and hosting](../activation-hosting.md)) | `src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs` | This operation |

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Activation and hosting](../activation-hosting.md)
- [Operations](../operations.md)
- [Faults and error pipeline](../faults.md)
- [Authentication and authorization](../authentication-authorization.md)
- [Dependencies](../dependencies.md)
- [Configuration](../configuration.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Data model](../data-model.md)
- [Operational runbook](../operational-runbook.md)
- [Tech debt](../tech-debt.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs
